package com.hbsx.why.ui.mine;

import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.hbsx.why.R;
import com.hbsx.why.base.BaseActivity;
import com.hbsx.why.utils.CommonUtils;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;

import java.util.Date;

import butterknife.BindView;

/**
 * Created by User on 2017/2/22.
 */

public class SignActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.calendarView)
    MaterialCalendarView calendarView;
    @BindView(R.id.ui_sign_txtBtn)
    TextView signTxt;
    @BindView(R.id.tv_topTitle)
    TextView tvTopTitle;

    private boolean signType;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        onInit();
    }

    @Override
    protected int getLayoutResId() {
//        setContentView(R.layout.ui_mine_sign);
        return R.layout.ui_mine_sign;
    }

    @Override
    protected void initView() {

    }

    protected void onInit() {
        tvTopTitle.setText("签到");
        calendarView.setSelectedDate(new Date());
        findViewById(R.id.ui_sign_layout).setOnClickListener(this);
    }

    private void initData() {
        signTxt.setText("已签到");
//        Call<BasePageModel> call = HttpAdapter.getService().getUserSign(XiaoLuApplication.get().getUserModel().getCode());
//        call.enqueue(new OnResponseListener<BasePageModel>(this) {
//            @Override
//            protected void onSuccess(BasePageModel diaryDetailModelBaseResultModel) {
//                if(diaryDetailModelBaseResultModel.getData().getPageCount()==0){
//                    signTxt.setText("签到");
//                    signType = true;
//                }else{
//                    signTxt.setText("已签到");
//                    signType = false;
//                }
//            }
//            @Override
//            protected void onFailure(String msg) {
//                super.onFailure(msg);
//                Log.e("zp","Failur="+msg);
//            }
//        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ui_sign_layout:
                if (signType) {
//                    Call<BaseResultModel> call = HttpAdapter.getService().userSign(XiaoLuApplication.get().getUserModel().getCode());
//                    call.enqueue(new OnResponseListener<BaseResultModel>(this) {
//                        @Override
//                        protected void onSuccess(BaseResultModel diaryDetailModelBaseResultModel) {
//                            if(diaryDetailModelBaseResultModel.getCode() == 200){
//                                signTxt.setText("已签到");
//                                signType = false;
//                            }else{
//                                signTxt.setText("签到");
//                                signType = true;
//                            }
//                        }
//
//                        @Override
//                        protected void onFailure(String msg) {
//                            super.onFailure(msg);
//                            Log.e("zp","Failur="+msg);
//                        }
//                    });
                } else {
                    Toast.makeText(getContext(), "您今日已签到！", Toast.LENGTH_LONG).show();
//     showToast("您今日已签到！");
                }
                break;
        }
    }
}
